#include <iostream>
#include <cstdlib>
#include <cstring>
using std::cin;
using std::cout;
using std::endl;
int main()
{
#if 0
    char *str = (char *)malloc(sizeof(char) * 10);
    char **doubleStr = (char **)malloc(sizeof(char *) * 3);
    if (!doubleStr)
    {
        return -1;
    }
    for (int idx = 0; idx < 3; idx++)
    {
        doubleStr[idx] = (char *)malloc(sizeof(char) * (10));
        if (!doubleStr[idx])
        {
            return -1;
        }
        strncpy(doubleStr[idx], "hello", sizeof(doubleStr[idx]) - 1);
    }
    if (str == NULL)
    {
        return 111;
    }
    strncpy(str, "hello", sizeof(str) - 1);
    std::cout << str << std::endl;
    for (int idx = 0; idx < 3; idx++)
    {
        std::cout << doubleStr[idx] << std::endl;
    }
    free(str);
    for (int idx = 0; idx < 3; idx++)
    {
        free(doubleStr[idx]);
    }
    free(doubleStr);
#endif
    char *s = new char[10];
    char **doubleStr = new char *[3];
    /*不需要计算内存的大小*/
    /*不需要对指针进行转换*/
    /*不需要判断指针是否为空：抛出异常，终止程序*/
    for (int idx = 0; idx < 3; idx++)
    {
        doubleStr[idx] = new char[10];
        strncpy(doubleStr[idx], "hello", sizeof(doubleStr[idx]) - 1);
    }
    for (int idx = 0; idx < 3; idx++)
    {
        std::cout << doubleStr[idx] << std::endl;
    }
    int *a = new int(10); /*小括号是赋值，[]申请数组*/
    delete a;
    // delete[] s;
    delete s;
    for (int idx = 0; idx < 3; idx++)
    {
        delete[] doubleStr[idx];
    }
    delete[] doubleStr;
    return 0;
}